// CustomFilter.cpp : implementation file
//

#include "stdafx.h"
#include "ImageLab.h"
#include "CustomFilter.h"
#include "ChildFrm.h"


// CCustomFilter dialog

IMPLEMENT_DYNAMIC(CCustomFilter, CDialog)

CCustomFilter::CCustomFilter(CWnd* pParent /*=NULL*/)
	: CDialog(CCustomFilter::IDD, pParent)
{
	ASSERT(pParent!=NULL);
	m_Parent = pParent;
	m_nID = CCustomFilter::IDD;
	::AfxInitRichEdit2();
}

CCustomFilter::~CCustomFilter()
{
}

void CCustomFilter::DoDataExchange(CDataExchange* pDX)
{
	//DDX_Control(pDX, IDC_CF_CUSTOMMASK, test);
	CDialog::DoDataExchange(pDX);
	DDX_Text(pDX, IDC_CF_NUMERATOR, m_Numerator);
	DDX_Text(pDX, IDC_CF_DENOMINATOR, m_Denominator);
	DDX_Text(pDX, IDC_CF_CUSTOMMASK, m_CustomMask);
}

BEGIN_MESSAGE_MAP(CCustomFilter, CDialog)
	ON_BN_CLICKED(IDC_CF_APPLY, &CCustomFilter::OnBnClickedCfApply)
	ON_BN_CLICKED(IDC_CF_CLEAR, &CCustomFilter::OnBnClickedCfClear)
END_MESSAGE_MAP()

BOOL CCustomFilter::Create()
{
	BOOL hResult = CDialog::Create(m_nID, m_Parent);
	if(hResult==FALSE)
		return hResult;
	CCustomFilter::SetFonts();
	return hResult;
}


// CCustomFilter message handlers

void CCustomFilter::OnBnClickedCfApply()
{
	OnOK();
	return;
}

void CCustomFilter::OnBnClickedCfClear()
{
	CEdit* m_Edit = (CEdit*)CCustomFilter::GetDlgItem(IDC_CF_CUSTOMMASK);
	m_Edit->SetWindowTextW(_T(""));
	m_Edit->Clear();
	return;
}

void CCustomFilter::SetFonts()
{
	// Constructor stuff here
	CString Instructions;
	Instructions += "Instructions:\n";
	Instructions += "Enter an m x m square mask into the edit box provided. ";
	Instructions += "Separate each number with a space, and press ENTER for each new line. ";
	Instructions += "Enter a scaling factor into the box provided if necessary.";
	::AfxMessageBox(Instructions, MB_OK, 0);

	// Change the font of the edit boxes
	CRichEditCtrl* m_RichEditCtrl1 = (CRichEditCtrl*)CCustomFilter::GetDlgItem(IDC_CF_CUSTOMMASK);
	CRichEditCtrl* m_RichEditCtrl2 = (CRichEditCtrl*)CCustomFilter::GetDlgItem(IDC_CF_NUMERATOR);
	CRichEditCtrl* m_RichEditCtrl3 = (CRichEditCtrl*)CCustomFilter::GetDlgItem(IDC_CF_DENOMINATOR);
	CFont font;
	font.CreatePointFont(120, _T("Courier"));
	m_RichEditCtrl1->SetFont(&font,1);
	m_RichEditCtrl2->SetFont(&font,1);
	m_RichEditCtrl3->SetFont(&font,1);
	m_RichEditCtrl1->SetWindowTextW(_T(""));
	m_RichEditCtrl2->SetWindowTextW(_T("1"));
	m_RichEditCtrl3->SetWindowTextW(_T("1"));

	return;
}
